home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 April
/
PCWorld_2008-04_cd.bin
/
komercni software
/
miton
/
SystemMechanic7Pro.exe
/
{app}
/
smhtml.dll
/
1033
/
HTML
/
DATATABLE.JS
< prev
next >
Wrap
Text File
|
2008-01-24
|
11KB
|
463 lines
function DataTable()
{
this.ID = "";
this.Class = "";
this.Style = "";
this.Width = "";
this.LabelClass = "NOT_ASSIGNED";
this.ValueClass = "NOT_ASSIGNED";
this.ItemClass = "NOT_ASSIGNED";
this.AlternateItemClass = "NOT_ASSIGNED";
this.Border = "0";
this.Cellspacing = "1";
this.Cellpadding = "3";
this.Items = new Array();
this.Render = __RenderDataTable;
this.Add = __AddItemToDataTable;
this.AddWithKey = __AddItemToDataTableWithKey;
this.AddWithKeyByIndex = __AddItemToDataTableWithKeyByIndex;
this.ChangeCellbyKey = __ChangeDataTableCellbyKey; // change cell by using primary key (does't work in firefox)
this.ChangeCell = __ChangeDataTableCell;
this.ChangeClassInRowByIndex = __ChangeClassInRowByIndex;
this.DeleteRow = __DeleteRow; // delete row by using primary key
this.DeleteRowByIndex = __DeleteRowByIndex;
this.Alternate = __Alternate;
this.Clear = __DataTableClearAllItems;
this.Count = __DataTableRowCount;
this._Rendered = false;
this._ClientID = __ClientID;
}
function __ClientID()
{
return "datatable_tbl_" + this.ID;
}
function __DataTableRowCount()
{
var tbl = Get("datatable_tbl_" + this.ID);
if ( tbl == null )
return 0;
var tbody = tbl.childNodes[0];
return tbody.rows.length;
}
function __DataTableClearAllItems()
{
var tbl = Get("datatable_tbl_" + this.ID);
if ( tbl == null )
return;
var count = tbl.childNodes[0].rows.length;
for( var x=0; x< count; x++ )
tbl.deleteRow(0);
}
function DataTableItem()
{
this.Items; // array of values
// id of the parent table
this.ParentID = "";
this.PrimaryKey = false;
this.Label;
this.Value;
this.ItemClass = "NOT_ASSIGNED";
this.AlternateItemClass = "NOT_ASSIGNED";
this.Render = __RenderDataTableItem;
}
function __RenderDataTable()
{
var content = "";
content += "<table id=\"datatable_tbl_" + this.ID + "\"cellspacing=\"" + this.Cellspacing + "\" cellpadding=\"" + this.Cellpadding + "\" border=\"" + this.Border + "\"";
if (this.Width != "")
content += " width=\"" + this.Width + "\"";
if (this.Class != "")
content += " class=\"" + this.Class + "\"";
content += ">";
for (var x = 0; x < this.Items.length; x++)
{
content += this.Items[x].Render(x);
}
content += "</table>";
this._Rendered = true;
return content;
}
function __RenderDataTableItem()
{
var content = "";
var id = "";
var start = 0;
if ( this.Items[0] != "" && this.Items[0] != null && this.PrimaryKey)
{
id = "id=\"tr_" + this.ParentID + "_" + this.Items[0] + "\"";
start = 1;
}
if ( arguments.length )
{
var x = arguments[0];
if(x % 2 == 0)
{
content += "<tr valign=\"top\" "+ id +" class=\""+ this.ItemClass +"\">";
}
else
{
content += "<tr valign=\"top\" "+ id +" class=\""+ this.AlternateItemClass +"\">";
}
}
else
{
content += "<tr valign=\"top\" "+ id +" >";
}
for ( x = start; x < this.Items.length; x++)
{
content += "<td >";
content += this.Items[x];
content += "</td>";
}
content += "</tr>";
return content;
}
// Adding a new row to the table
function __AddItemToDataTable()
{
var item = new DataTableItem();
item.ParentID = this.ID;
// values
item.Items = arguments;
// array of values passed
if( arguments[0].length > 1 && arguments.length==1)
item.Items[0] = arguments[0];
//item.Label = label;
//item.Value = value;
item.LabelClass = this.LabelClass;
item.ValueClass = this.ValueClass;
item.ItemClass = this.ItemClass;
item.AlternateItemClass = this.AlternateItemClass;
if( Get("datatable_tbl_" + this.ID) != null )
{
// The data table has already been rendered, so we need to manually
// add the data table item.
var tbl = Get("datatable_tbl_" + this.ID);
if ( tbl == null )
return;
var tbody ;
var row ;
//workaround for firefox
if ( tbl.childNodes.length == 0 )
{
//firefox
row=tbl.insertRow(0);
}
else
{
// ie
tbody = tbl.childNodes[0];
row = tbody.insertRow(tbody.rows.length);
}
var cell = null;
for (var x = 0; x < item.Items.length; x++)
{
cell = row.insertCell(row.cells.length);
cell.innerHTML = item.Items[x];
}
}
this.Items[this.Items.length] = item;
// recalculate row background colors
this.Alternate();
}
// Adding a new row to the table
// Example : suppose columns = 3, "__AddItemToDataTable(pk, v1, v2, v3)"
// the first value is taken as the primarykey and will not add to the row
function __AddItemToDataTableWithKey()
{
var item = new DataTableItem();
item.ParentID = this.ID;
item.PrimaryKey = true;
// values array
item.Items = arguments;
// array of values passed
if( arguments[0].length > 1 && arguments.length==1)
item.Items[0] = arguments[0];
//item.Label = label;
//item.Value = value;
item.LabelClass = this.LabelClass;
item.ValueClass = this.ValueClass;
item.ItemClass = this.ItemClass;
item.AlternateItemClass = this.AlternateItemClass;
var tbl = Get("datatable_tbl_" + this.ID);
if (tbl != null)
{
// The data table has already been rendered, so we need to manually
// add the data table item.
var tbody ;
var row ;
//workaround for firefox
if ( tbl.childNodes.length == 0 )
{
//firefox
row=tbl.insertRow(0);
}
else
{
// ie
tbody = tbl.childNodes[0];
row = tbody.insertRow(tbody.rows.length);
}
//take the first value as the primary key
if ( item.Items[0] != null)
{
// adding the primary key to the table row 'id'
var rowid = "tr_" + this.ID + "_" + item.Items[0];
row.setAttribute('id', rowid );
}
var cell = null;
for (var x = 1; x < item.Items.length; x++)
{
cell = row.insertCell(row.cells.length);
cell.innerHTML = item.Items[x];
}
}
this.Items[this.Items.length] = item;
// recalculate row background colors
this.Alternate();
}
// Adding a new row to the table
// Example : suppose columns = 3, "__AddItemToDataTable(pk,index, v1, v2, v3)"
// the first value is taken as the primarykey and will not add to the row
function __AddItemToDataTableWithKeyByIndex()
{
var item = new DataTableItem();
item.ParentID = this.ID;
item.PrimaryKey = true;
// values array
item.Items = arguments;
// array of values passed
if( arguments[0].length > 1 && arguments.length==1)
item.Items[0] = arguments[0];
//item.Label = label;
//item.Value = value;
item.LabelClass = this.LabelClass;
item.ValueClass = this.ValueClass;
item.ItemClass = this.ItemClass;
item.AlternateItemClass = this.AlternateItemClass;
var tbl = Get("datatable_tbl_" + this.ID);
if (tbl != null)
{
// The data table has already been rendered, so we need to manually
// add the data table item.
var tbody ;
var row ;
var index = item.Items[1]
//workaround for firefox
if ( tbl.childNodes.length == 0 )
{
//firefox
row=tbl.insertRow(index);
}
else
{
// ie
tbody = tbl.childNodes[0];
row = tbody.insertRow(index);
}
//take the first value as the primary key
if ( item.Items[0] != null)
{
// adding the primary key to the table row 'id'
var rowid = "tr_" + this.ID + "_" + item.Items[0];
row.setAttribute('id', rowid );
}
var cell = null;
for (var x = 2; x < item.Items.length; x++)
{
cell = row.insertCell(row.cells.length);
cell.innerHTML = item.Items[x];
}
}
this.Items[this.Items.length] = item;
// recalculate row background colors
this.Alternate();
}
function __ChangeDataTableCellbyKey( text , pkValue , column )
{
var tbl = Get("datatable_tbl_" + this.ID);
var rowID = "tr_" + this.ID + "_" + pkValue;
var row = Get ( rowID );
if( row == null )
return;
this.ChangeCell( text , row.rowIndex, column );
}
function __ChangeDataTableCell(text, row, column)
{
var element = document.getElementById("datatable_tbl_" + this.ID);
var tbody = element.childNodes[0];
var row = tbody.rows[row];
var cell = row.cells[column];
cell.innerHTML = text;
}
function __ChangeClassInRowByIndex(index, Class)
{
var element = document.getElementById("datatable_tbl_" + this.ID);
if(element == null)
return;
var tbody = element.childNodes[0];
var row = tbody.rows[index];
row.className = Class;
}
//delete row by primary key
function __DeleteRow( pkValue )
{
var tbl = Get("datatable_tbl_" + this.ID);
var rowID = "tr_" + this.ID + "_" + pkValue;
var row = Get ( rowID );
if( row == null )
return;
this.DeleteRowByIndex( row.rowIndex );
}
function __DeleteRowByIndex( index )
{
var tbl = Get("datatable_tbl_" + this.ID);
// table is not found or index is out of range
if ( tbl == null || ( tbl.rows.length < index+1))
return;
else
this._Rendered = true;
tbl.deleteRow( index );
//recalculate row background colours
this.Alternate();
}
function __Alternate()
{
// if table is not rendered return
var tbl = Get("datatable_tbl_" + this.ID);
if (! tbl ==null )
return;
if (this.ItemClass == "NOT_ASSIGNED" )
return;
if (this.AlternateItemClass == "NOT_ASSIGNED" )
this.AlternateItemClass = this.ItemClass;
var table = Get("datatable_tbl_" + this.ID);
if (table == null )
return;
var rows = table.rows;
for(i = 0; i < rows.length; i++)
{
if(i % 2 == 0)
{
rows[i].className = this.ItemClass;
}
else
{
rows[i].className = this.AlternateItemClass;
}
}
}